﻿using Max.PH5_2010A.Shopping.DataAccess;
using Max.PH5_2010A.Shopping.Domain;
using Max.PH5_2010A.Shopping.IRespository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2010A.Shopping.Respository
{
    public class BaseRespository<T> : IBaseRespository<T> where T :class,new()
    {
        MaxPH52010AShoppingDbContext _context;

        public BaseRespository(MaxPH52010AShoppingDbContext context)
        {
            _context = context;
        }

        public void Delete(List<T> t)
        {
            _context.Set<T>().RemoveRange(t);
            //_context.SaveChanges();   //避免做一次就提交一次，之后用事务来保证
        }

        public void Insert(T t)
        {
            _context.Set<T>().Add(t);
        }

        public void Insert(List<T> t)
        {
            _context.Set<T>().AddRange(t);
        }

        public IQueryable<T> Select()
        {
            return _context.Set<T>();
        }

        public void Update(T t)
        {
            _context.Set<T>().Update(t);
        }
    }
}
